<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>住院列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
    <script src="../../../lib/layui-v2.6.3/layui.js" charset="UTF-8"></script>
    <script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">








             <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
             <table class="layui-hide" id="currentTableId1" lay-filter="currentTableFilter1"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit"  lay-event="query">药品查询</a>
        </script>
        <script type="text/html" id="currentTableBar1">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit  " lay-event="delete">结算</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="update">修改</a>
        </script>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
            </div>
        </script>


    </div>
</div>
<script src="../../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/api/inhosiptal/pageWhere.do',
            where:{uname:""}, //初始化的查询条件
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', title: 'ID', sort: true},
                {field: 'uname', title: '姓名',width:'13%'},
                {field: 'age', title: '年龄',width:'13%'},
                {field: 'sex', title: '性别',width:'13%'},
                {field: 'dname', title: '医生',width:'13%'},
                {title: '操作', minWidth: 200, toolbar: '#currentTableBar'}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });


        table.render({
            elem: '#currentTableId1',
            url: '/api/painhosdrug/pagewhere.do',
            where:{regid:""}, //初始化的查询条件
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'regid', title: 'id',width:'13%'},
                {field: 'drugname', title: '药品名',width:'13%'},
                {field: 'drugnum', title: '药品数量',width:'13%'},
                {field: 'price', title: '药品单价',width:'13%'},
                {field: 'price1',title: '药品总价', templet: function(d){
                          return '<span class="spred">'+d.drugnum*d.price+'</span>';

                    },width:'13%'},
                {title: '操作', minWidth: 200, toolbar: '#currentTableBar1', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });


        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter1)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加药品',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'painhosdrugAdd.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }

        });



        table.on('tool(currentTableFilter)', function (obj) {
            if (obj.event === 'query') {  // 监听添加操作
             /*  /!* var data = obj.data;
                localStorage.setItem("record",JSON.stringify(data));*!/
                alert(obj.data.id)
*/
                //执行搜索重载
                table.reload('currentTableId1',{
                     where: {regid:obj.data.id},
                    page: {
                        curr: 1
                    }

            }, 'obj');

               /* $.post("/api/painhosdrug/pagewhere.do",obj.data.id,function(res){
                    if(res.code==200){
                        //成功



                    }else{
                        //失败
                        layer.msg('查询失败！');
                    }
                });*/


                return false;
            }
        });




                table.on('tool(currentTableFilter1)', function (obj) {
            var data = obj.data;
            if (obj.event === 'update') {
                localStorage.setItem("record",JSON.stringify(data));
                var index = layer.open({
                    title: '编辑药品',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'painhosdrugEdit.html',
                });
                $(window).on("painhosDrug", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的结账吗：'+data.drugname, function (index) {
                    //请求后端接口地址，Ajax
                    $.post("/api/painhosdrug/del.do","id="+data.id,function(res){
                        if(res.code==200){
                            //删除成功
                            obj.del();//删除表格的对应数据
                        }else{
                            layer.msg("亲，结账失败！");
                        }
                    });
                    layer.close(index);
                });
            }

        });

    });
</script>

</body>
</html>